package com.example.basicdemo.controller;

import com.isyscore.os.dev.api.dmc.model.builder.AddDeviceGroupRequestBuilder;
import com.isyscore.os.dev.api.dmc.model.builder.AddDeviceRequestBuilder;
import com.isyscore.os.dev.api.dmc.model.result.AddDeviceGroupResult;
import com.isyscore.os.dev.api.dmc.model.result.AddDeviceResult;
import com.isyscore.os.dev.api.dmc.service.DmcService;
import com.isyscore.os.dev.util.IsyscoreHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 该控制器集成了以下iSysCore OS的设备管理能力
 */
public class DeviceController {

    @Autowired
    private DmcService dmcService;


    private static IsyscoreHashMap header = new IsyscoreHashMap();

    /**
     * 新增设备功能
     */
    @GetMapping("addDevice")
    public void addDevice(@RequestBody AddDeviceRequestBuilder builder) {
        //构建参数
//        AddDeviceRequestBuilder builder = new AddDeviceRequestBuilder()
//                .setCity("杭州")
//                //设置请求头
//                .setHeaders(header);
        //根据request设置请求头
        //.setRequestHeader(request);

        //接口函数调用
        AddDeviceResult result = dmcService.addDevice(builder);
        //判断结果是否成功
        System.out.println("success: " + result.isSuccess());
        //获取httpCode:http请求结果的code码
        System.out.println("httpCode: " + result.getResponse().getHttpCode());
        //获取httpMessage:http请求结果的消息
        System.out.println("httpMessage: " + result.getResponse().getHttpMessage());
        //获取code:接口返回的错误码
        System.out.println("code: " + result.getResponse().getCode());
        //获取message:接口返回的错误消息
        System.out.println("message: " + result.getResponse().getMessage());
        //获取detail:接口返回的错误附带详情
        System.out.println("detail: " + result.getResponse().getDetail());
        //获取结果数据
        System.out.println("body: " + result.getResponse().getBody());
        //解析结果数据(Json 转 Object)
        System.out.println("parseData: " + result.parseListData());
    }

    /**
     * 新增设备组
     */
    @GetMapping("addDeviceGroup")
    public void addDeviceGroup(@RequestBody AddDeviceGroupRequestBuilder builder) {
        //构建参数
//        AddDeviceGroupRequestBuilder builder = new AddDeviceGroupRequestBuilder()
        //根据request设置请求头
        //.setRequestHeader(request);

        //接口函数调用
        AddDeviceGroupResult result = dmcService.addDeviceGroup(builder);
        //判断结果是否成功
        System.out.println("success: " + result.isSuccess());
        //获取httpCode:http请求结果的code码
        System.out.println("httpCode: " + result.getResponse().getHttpCode());
        //获取httpMessage:http请求结果的消息
        System.out.println("httpMessage: " + result.getResponse().getHttpMessage());
        //获取code:接口返回的错误码
        System.out.println("code: " + result.getResponse().getCode());
        //获取message:接口返回的错误消息
        System.out.println("message: " + result.getResponse().getMessage());
        //获取detail:接口返回的错误附带详情
        System.out.println("detail: " + result.getResponse().getDetail());
        //获取结果数据
        System.out.println("body: " + result.getResponse().getBody());
        //解析结果数据(Json 转 Object)
        System.out.println("parseData: " + result.parseListData());
    }


}
